cmake_minimum_required(VERSION 3.12)
project(ar3pc VERSION 1.5.19.2)
configure_file(config.h.in config.h)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# set(ZHNMAT_DIR D:/cppcode/zhnmat)
set(ZHNMAT_DIR /home/pi/Desktop/myfile/cpp/zhnmat)

find_package(Qt5Widgets REQUIRED)
find_package(Qt5SerialPort REQUIRED)

option(IF_DEBUG "Debug this project." OFF)
option(USE_OPENCV "If you can use OpenCV." ON)
option(USE_QTCHART "If you can use QtChart." OFF)

message(STATUS "project name: ${CMAKE_PROJECT_NAME}")
message(STATUS "project version: ${PROJECT_VERSION}")
message(STATUS "project build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "if use opencv: ${USE_OPENCV}")
message(STATUS "if use qtchart: ${USE_QTCHART}")

set(PROJECT_SOURCES
    ${PROJECT_SOURCE_DIR}/user/main.cpp
    ${PROJECT_SOURCE_DIR}/user/widget.cpp
    ${PROJECT_SOURCE_DIR}/user/ui.cpp
    ${PROJECT_SOURCE_DIR}/user/slots.cpp
    ${PROJECT_SOURCE_DIR}/user/serialport.cpp
    ${PROJECT_SOURCE_DIR}/user/protocol.cpp
    ${PROJECT_SOURCE_DIR}/user/kinematic.cpp
    ${PROJECT_SOURCE_DIR}/user/file.cpp
)

set(PROJECT_LIBRARIES
    ${ZHNMAT_DIR}/build/libzhnmat.a
    Qt5::Widgets
    Qt5::SerialPort
)

if(IF_DEBUG)
    set(CMAKE_BUILD_TYPE debug)
else()
    set(CMAKE_BUILD_TYPE release)
endif()

if(USE_OPENCV)
    find_package(OpenCV REQUIRED)
    set(VISION_SOURCES ${PROJECT_SOURCE_DIR}/user/vision.cpp)
    set(VISION_LIBRIES ${OpenCV_LIBS})
    add_definitions(-DUSE_OPENCV)
    message(STATUS "OpenCV config: ${OpenCV_DIR}")
    message(STATUS "OpenCV include path: ${OpenCV_INCLUDE_DIRS}")
    message(STATUS "OpenCV version: ${OpenCV_VERSION}")
else()
    set(VISION_SOURCES )
    set(VISION_LIBRIES )
endif()

if(USE_QTCHART)
    find_package(Qt5Charts REQUIRED)
    set(CHART_LIBRIES Qt5::Charts)
    add_definitions(-DUSE_QTCHART)
else()
    set(CHART_LIBRIES )
endif()

add_executable(${CMAKE_PROJECT_NAME}_exe ${PROJECT_SOURCES} ${VISION_SOURCES})
target_link_libraries(${CMAKE_PROJECT_NAME}_exe PRIVATE
    ${PROJECT_LIBRARIES}
    ${VISION_LIBRIES}
    ${CHART_LIBRIES}
)
target_include_directories(${CMAKE_PROJECT_NAME}_exe PUBLIC "${PROJECT_BINARY_DIR}")
target_include_directories(${CMAKE_PROJECT_NAME}_exe PUBLIC "${ZHNMAT_DIR}")
